﻿@model LuxDiner.Model.Members.CustomerModel


<div class="GeneralEdit" id="fmCustomer">
    <ul>
        <li>
            <label for="txtCustomerNo">客户编码：</label>
            <input type="text" class="k-textbox" id="txtCustomerNo" name="customerNo" value="@Model.CustomerNo" pattern=".{2,}" required validationMessage="请输入客户编码" />
            <span class="k-invalid-msg" data-for="customerNo"></span>
        </li>
        <li>
            <label for="txtCorporation">公司名称：</label>
            <input type="text" class="k-textbox" id="txtCorporation" name="corporation" value="@Model.Corporation" maxlength="50" pattern=".{2,}" required validationMessage="请输入公司名称" />
            <span class="k-invalid-msg" data-for="corporation"></span>
        </li>
        <li>
            <label for="txtRealName">联系人姓名：</label>
            <input type="text" class="k-textbox" id="txtRealName" name="realname" value="@Model.RealName" maxlength="50" pattern=".{2,}" required validationMessage="请输入联系人姓名" />
            <span class="k-invalid-msg" data-for="realname"></span>
        </li>
        <li>
            <label for="txtAddress">地址：</label>
            <input type="text" class="k-textbox" id="txtAddress" name="address" value="@Model.Address" maxlength="50" />
        </li>
        <li>
            <label for="txtMobile">手机号码：</label>
            <input type="text" class="k-textbox" id="txtMobile" name="mobile" value="@Model.Mobile" maxlength="20" />
        </li>
        <li>
            <label for="ddlType">类型：</label>
            <select id="ddlType">
                <option value="1" @(Model.CType==1?"selected='selected'":"")>顾客</option>
                <option value="2" @(Model.CType==2?"selected='selected'":"")>供应商</option>
            </select>
        </li>
        <li>
            <label for="ddlCategories">所属分类：</label>

            <select id="ddlCategories" multiple="multiple" data-placeholder="选择分类...">
                @foreach (var cat in (LuxDiner.Model.Members.CustomerCategoryCollection)ViewBag.Categories)
                {
                    <option value="@cat.ID" @((Model.Categories != null && Model.Categories.Any(p => p.ID == cat.ID)) ? "selected=\"selected\"" : "") >@cat.CategoryName</option>    
                }
            </select>
        </li>
        <li>
            <label for="txtSortIndex">排序号：</label>
            <input type="number" class="k-textbox" id="txtSortIndex" name="sortIndex" value="@Model.SortIndex" min="0" required validationMessage="请输入排序号"/>
            <span class="k-invalid-msg" data-for="sortIndex"></span>
        </li>
        <li>
            <label for="ddlStatus">状态：</label>
            <select id="ddlStatus">
                <option value="1" @(Model.Status==1?"selected='selected'":"")>正常</option>
                <option value="2" @(Model.Status==2?"selected='selected'":"")>禁用</option>
            </select>
        </li>
        <li class="editButtons">
            <button id="btnSaveCustomer" class="k-button"><span class="k-icon k-i-tick"></span><span>确认提交</span></button>
            &nbsp;&nbsp;
            <button class="k-button" onclick="CancelGeneralEdit();"><span class="k-icon k-i-cancel"></span><span>&nbsp;返&nbsp;回</span></button>
        </li>
    </ul>
</div>

<script class="save_customer">
    $("#ddlStatus").kendoDropDownList();
    $("#ddlCategories").kendoMultiSelect();
    $("#ddlType").kendoDropDownList();
    $(function () {
        var validator = $("#fmCustomer").kendoValidator().data("kendoValidator");
        $("#btnSaveCustomer").click(function (e) {
            if (validator.validate()) {
                var values = {
                    customerID: "@Model.ID",
                    customerNo:$("#txtCustomerNo").val(),
                    corporation: $("#txtCorporation").val(),
                    realname: $("#txtRealName").val(),
                    address: $("#txtAddress").val(),
                    mobile: $("#txtMobile").val(),
                    categories: $("#ddlCategories").data("kendoMultiSelect").value().join(','),
                    cType: $("#ddlType").data("kendoDropDownList").value(),
                    status: $("#ddlStatus").data("kendoDropDownList").value(),
                    sortIndex: $("#txtSortIndex").val(),
                };

                Whale.Remote.Operation({
                    url: "/Members/Customer/Save",
                    parameters: values,
                    success: function (result) {
                        wndGeneralEdit.close();
                        if ($("#grid_customer").length > 0)
                            $("#grid_customer").data("kendoGrid").dataSource.read();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            }
            return false;
        });
    });
</script>
